package com.example.shengyin.frontController;

import com.example.shengyin.entity.Page;
import com.example.shengyin.entity.Professor;
import com.example.shengyin.service.ProfessorService;
import com.example.shengyin.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("front/professor")
@Validated
@CrossOrigin(origins = "*", maxAge = 3600,allowCredentials="true")
//swagger
@Api(tags = "ProfessorFrontController", description = "专家")
public class ProfessorFrontController {
    @Autowired
    private ProfessorService service;


    @ApiOperation("预约列表")
    @GetMapping("/search")

    public Result event(@ApiParam(name = "pname",value = "预约人名") @RequestParam(required = false) String pname,
                        @ApiParam(name = "ptype" ,value = "专家类型") @RequestParam(required = false) String ptype,
                        @ApiParam(name = "pos" ,value = "区域") @RequestParam(required = false) String pos,
                        @RequestParam(name = "page",defaultValue = "1") int page,
                        @RequestParam(name = "limit",defaultValue = "10")int limit) {
        Page p = service.selectList(pname,ptype,pos, page, limit);
        int count = service.fand(pname,ptype,pos);
        if(count==0||p==null)
            return Result.error("没有数据");
        return Result.success(p);
    }

    @GetMapping(value = "/select/{id}")
    public Result select(@PathVariable(value = "id") Long id)
    {
        Professor select = service.selectById(id);
        if(select==null)
            return Result.error("没有找到数据");
        return Result.success(select);
    }
}
